<div style="width: 700px; margin-left: auto; margin-right: auto; text-align: center; border: solid 1px #dddddd; background: #eeeeee; padding: 10px">
  <form action="/media/search" method="get">
    <label for="query" style="font-weight: bold;">Search:</label>
    <%= text_field_tag 'query', params[:query], :size => '80' %>
    <%= submit_tag 'Search' %>
  </form>
</div>
<% unless @medias.nil? %>
<% if !params[:query].nil? or !params[:tag].nil? %>
<div style="padding-top: 10px;">
  <% for media in @medias do %>
    <% if media.mediable_type == 'ImageFile' %>
      <div class="thumbnail-box" onclick="if (!cancelLink) document.location='<%= url_for :action => 'show', :id => media.id, :permalink => media.permalink %>'">
        <div style="position: absolute; right: 5px; float: right; padding: 2px; background: #fff; border: solid 1px #cccccc;"><%= media.rating %></div>
        <div style="width: 200px; height: 200px; margin-left: auto; margin-right: auto;" class="thumbbox">
          <%= link_to_media_lightbox media.mediable.public_filename(:large), media.mediable.public_filename(:thumb) %>
          <div class='highslide-caption' style="visibility: hidden;">
            <h3 style="display: inline;"><%= link_to clean_text(media.title), :action => 'show', :id => media.id, :permalink => media.permalink %>: </h3><%= clean_text(media.description) %>
          </div>
        </div>
        <%= link_to clean_text(media.title), {:action => 'show', :id => media.id, :permalink => media.permalink}, {:onmouseover => 'cancelLink=true', :onmouseout => 'cancelLink=false'} %><br />
        <%= media.category.name unless media.category.nil? %><br />
        <%= link_to media.user.login, {:controller => 'account', :action => 'show', :id => media.user.login}, {:onmouseover => 'cancelLink=true', :onmouseout => 'cancelLink=false'} %> <%= distance_of_time_in_words_to_now(media.created_at) %> ago
      </div>
    <% else %>
      <div class="thumbnail-box" onclick="if (!cancelLink) document.location='<%= url_for :action => 'show', :id => media.id, :permalink => media.permalink %>'">
        <div style="position: absolute; right: 5px; float: right; padding: 2px; background: #fff; border: solid 1px #cccccc;"><%= media.rating %></div>
        <div style="width: 200px; height: 200px; margin-left: auto; margin-right: auto;" class="thumbbox">
          <%= link_to_partial_lightbox image_tag(media.mediable.public_filename + ".small.jpg", :style => 'border: 0;'), { :partial => "playvideo", :locals => { :video => "#{media.mediable.public_filename}.flv", :image => "#{media.mediable.public_filename}.jpg", :videoid => media.id } }, { :id => "media"+media.id.to_s } %>
          <div class='highslide-caption' style="visibility: hidden;">
            <h3 style="display: inline;"><%= link_to clean_text(media.title), :action => 'show', :id => media.id, :permalink => media.permalink %>: </h3><%= clean_text(media.description) %>
          </div>
        </div>
        <%= link_to clean_text(media.title), {:action => 'show', :id => media.id, :permalink => media.permalink}, {:onmouseover => 'cancelLink=true', :onmouseout => 'cancelLink=false'} %><br />
        <%= media.category.name unless media.category.nil? %><br />
        <%= link_to media.user.login, {:controller => 'account', :action => 'show', :id => media.user.login}, {:onmouseover => 'cancelLink=true', :onmouseout => 'cancelLink=false'} %> <%= distance_of_time_in_words_to_now(media.created_at) %> ago
      </div>
    <% end %>
  <% end %>
  <div class="clearer"></div>
  <div style="display: none;">
    <div id="controlbar" class="highslide-overlay controlbar">
    <a class="previous" title="Previous (left arrow key)" onclick="return hs.previous(this)" href="#"></a>
    <a class="next" title="Next (right arrow key)" onclick="return hs.next(this)" href="#"></a>
    <a class="highslide-move" title="Click and drag to move" onclick="return false" href="#"></a>
    <a class="close" title="Close" onclick="return hs.close(this)" href="#"></a>
    </div>
  </div>
</div>
<% end %>
<div style="text-align: center;">
<%= link_to('&laquo; Previous', :page => @pages.current.previous.number, :params => @query) if @pages.current.previous %>
<%= pagination_links(@pages, :params => @query) %>
<%= link_to('Next &raquo;', :page => @pages.current.next.number, :params => @query) if @pages.current.next %>
</div>
<% end %>
